package com.hanxry.simple;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * @author hanxry
 */
class MDCThread extends Thread {

    private static final Logger logger = LoggerFactory.getLogger(TheadDemo.class);
    public static final String TRACE_ID = "traceId";

    private final String flag;

    public MDCThread(String flag) {
        this.flag = flag;
    }


    @Override
    public void run() {
        MDC.put(TRACE_ID, UUID.randomUUID().toString());
        logger.info("开始调用服务{}", flag);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            logger.info(e.getMessage());
        }
        logger.info("服务{}处理完毕", flag);
        MDC.remove(TRACE_ID);
    }
}
